import request from "@/request/request";
import type { updateStatusParams, updateStatusItem } from "@/types/global";
// 菜单列表参数
interface menuListParams {
	pageNum?: number;
	pageSize?: number;
	parentId?: number;
}
// 菜单列表返回值
interface menuListRes {
	code: number;
	data: Data;
	message: string;
}

interface Data {
	list: updateStatusItem[];
	pageNum: number;
	pageSize: number;
	total: number;
	totalPage: number;
}
interface TreeListRes {
	code: number;
	data: TreeListItem[];
	message: string;
}

interface TreeListItem {
	children: null[];
	createTime: string;
	hidden: number;
	icon: string;
	id: number;
	level: number;
	name: string;
	parentId: number;
	sort: number;
	title: string;
}

// 菜单列表
export const menuListAPI = (data?: menuListParams): Promise<updateStatusItem> =>
	request.get(`/menu/list/${data?.parentId}?pageNum=${data?.pageNum}&pageSize=${data?.pageSize}`);
// 修改开关状态
export const updatedStatue = (data: updateStatusParams): Promise<updateStatusItem> =>
	request.post(`/menu/updateHidden/${data.id}?hidden=${data.hidden}`);
// 添加菜单
export const menuCreateAPI = (params: updateStatusItem): Promise<menuListRes> => request.post("/menu/create", params);
// id请求菜单详情
export const menuDetailAPI = (id: number): Promise<updateStatusItem> => request.get(`/admin/role/${id}`);
// 树形结构返回所有列表
export const treeListAPI = (): Promise<TreeListRes> => request.get("/menu/treeList");
